package com.test;

import com.mapper.TStudent;
import com.pojo.sqlSessionFactory;
import com.pojo.sqlSessionFactoryBuilder;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.Reader;
import java.util.List;


public class MyBatisTest {
    private SqlSessionFactory sqlSessionFactory;
    private SqlSession sqlSession;
    @BeforeEach
    public void init(){
        String resources = "mybatis-config.xml";
        Reader reader = null;
        try{
            reader= Resources.getResourceAsReader(resources);
            new sqlSessionFactoryBuilder().bulier(reader);
            sqlSession=sqlMapper.openSession();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    @Test
    public void findAllStudentTest(){
        List<TStudent> list =
                sqlSession.selectList("com.itheima.mapper.StudentMapper.findAllStudent");
                for(TStudent tStudent:list){
                    System.out.println(tStudent);
                }
    }
    @After
    public void destroy() {
        sqlSession.commit();
        sqlSession.close();
    }
    }

